﻿using System;
using System.Data;
using System.Collections.Generic;
using PPWMS.DAL;
using PPWMS.Model;
using PPWMS.Log;
namespace PPWMS.BLL
{
    /// <summary>
    /// Order
    /// </summary>
    public partial class Order
    {
        private PPWMS.DAL.Order dal = new PPWMS.DAL.Order();
        private PPWMS.Log.Logmanagement log = new Logmanagement();
        public Order(){ }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string OrderSubId)
        {
            bool re = false;
            try
            {
                re = dal.Exists(OrderSubId);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return re;
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PPWMS.Model.OrderModel model)
        {
            bool re = false;
            try
            {
                re = dal.Add(model);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return re;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PPWMS.Model.OrderModel model)
        {
            bool re = false;
            try
            {
                re = dal.Update(model);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return re;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string OrderSubId)
        {
            bool re = false;
            try
            {
                re = dal.Delete(OrderSubId);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return re;
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string OrderSubIdlist)
        {
            bool re = false;
            try
            {
                re = dal.DeleteList(OrderSubIdlist);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return re;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PPWMS.Model.OrderModel GetModel(string OrderSubId)
        {


            OrderModel re = null;
            try
            {
                re = dal.GetModel(OrderSubId);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return re;
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public PPWMS.Model.OrderModel GetModelByCache(string OrderSubId)
        {

            string CacheKey = "OrderModel-" + OrderSubId;
            object objModel = PPWMS.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(OrderSubId);
                    if (objModel != null)
                    {
                        int ModelCache = PPWMS.Common.ConfigHelper.GetConfigInt("ModelCache");
                        PPWMS.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch (Exception ex)
                {
                    log.WriteLog(ex.Message.ToString());
                }
            }
            return (PPWMS.Model.OrderModel)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            DataSet ds = null;
            try
            {
                ds = dal.GetList(strWhere);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return ds;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(OrderModel Order)
        {
            DataSet ds = null;
            try
            {
                ds = dal.GetList(Order);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return ds;
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            DataSet ds = null;
            try
            {
                ds = dal.GetList(Top, strWhere, filedOrder);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return ds;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PPWMS.Model.OrderModel> GetModelList(string strWhere)
        {
            DataSet ds = null;
            try
            {
                ds = dal.GetList(strWhere);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PPWMS.Model.OrderModel> DataTableToList(DataTable dt)
        {
            List<PPWMS.Model.OrderModel> modelList = new List<PPWMS.Model.OrderModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                try
                {
                    PPWMS.Model.OrderModel model;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        model = dal.DataRowToModel(dt.Rows[n]);
                        if (model != null)
                        {
                            modelList.Add(model);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.WriteLog(ex.Message.ToString());
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            DataSet ds = null;
            try
            {
                ds = GetList("");
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return ds;
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            int i = -1;
            try
            {
                i = dal.GetRecordCount(strWhere);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return i;
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            DataSet ds = null;
            try
            {
                ds = dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message.ToString());
            }
            return ds;
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod

    }
}

